package com.droidnow.droidaudio;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class HomeActivity extends Activity {
	/**
	 * Called when the activity is first created.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		this.initialize();
	}

	private boolean isPLAYING = false;
	private Button btnPlay;
	private Button btnBooks;
	private MediaPlayer mp;

	public void initialize() {
		this.btnPlay = (Button) this.findViewById(R.id.btnPlay);

		this.btnPlay.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if (!isPLAYING) {
					isPLAYING = true;
					mp = MediaPlayer.create(HomeActivity.this, R.raw.preview_au);
					mp.start();
				} else {
					isPLAYING = false;
					stopPlaying();
				}
			}
		});
		this.btnBooks = (Button) this.findViewById(R.id.btnBooks);

		this.btnBooks.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(HomeActivity.this, SuiteListActivity.class);
				startActivity(intent);
			}
		});

	}

	private void stopPlaying() {
		this.mp.release();
		this.mp = null;
	}
}
